<template>
  <div class="app-container table-app-container">
    <div class="fixed-table">
      <div class="fixed-table-actionbar">
        <TableFilter />
        <ActionBar />
      </div>
      <PageableTable
        :loading="loading"
        :data="insideTableData"
        :total="totalElements"
        :page="currentPage"
        :page-size="pageSize"
        :table-height="tableHeight"
        class="fixed-table-table"
        :multiple-selected="false"
        @page-change="onPageChange"
        @sort-change="onSortChange"
      >
        <el-table-column v-for="column in insideColumns" :key="column.key" :label="column.title" :prop="column.key" :sortable="column.sortable">
          <template slot-scope="scope">
            <column-render :render="column.render" :row="scope.row" :column="column" />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="230" class-name="small-padding fixed-width">
          <template slot-scope="{row}">
            <el-button type="text" title="编辑" size="mini" icon="el-icon-edit" @click="edit(row.id)" />
            <!-- <el-button type="text" title="修改结果" size="mini" icon="el-icon-view" @click="editResult(row.id)" /> -->
            <el-button type="text" title="删除" size="mini" icon="el-icon-delete" @click="remove(row.id)" />
          </template>
        </el-table-column>
      </PageableTable>
    </div>
    <FormDialog title="编辑" :show.sync="dialogFormVisible" width="90%" @on-ok="ok" @on-cancel="cancel">
      <EditForm v-if="dialogFormVisible" :id="editId" ref="editForm" />
    </FormDialog>
  </div>
</template>

<script>
// secondary package based on el-pagination
import { formatDate } from '@neu/biz-core/utils/utils'
import FormDialog from '@neu/biz-core/components/FormDialog'
// 表格查询组件独立编写，需要传递pageable-table实例的mixin方法filter
import TableFilter from './components/tableFilter'
// 编辑实例组件独立编写，需要传递id属性，判断新建还是更新操作
import EditForm from './components/editForm'
import ActionBar from './components/actionBar'
import PageableTable from '@neu/biz-core/components/PageableTable'
import databind from '@neu/biz-core/mixins/databind'
import {
  page,
  remove
} from '@neu/dcom-ui/api/dutyArrangement'
export default {
  name: 'DutyArrangementPage',
  components: {
    TableFilter,
    FormDialog,
    EditForm,
    ActionBar,
    PageableTable
    // ResultForm
  },
  // 加入混入，使表格混入更多的api操作
  mixins: [databind],
  data() {
    return {
      r: page,
      d: remove,
      insideColumns: [
        {
          title: '名称',
          key: 'name',
          sortable: 'custom'
        },
        {
          title: '管理部门',
          key: 'orgName',
          sortable: 'custom'
        },
        {
          title: '职能',
          key: 'functionalGroupName',
          sortable: 'custom'
        },
        {
          title: '规则',
          key: 'schedulingRuleName',
          sortable: 'custom'
        },
        {
          title: '开始时间',
          key: 'startTime',
          sortable: 'custom',
          render: (h, params) => {
            return (<span> { formatDate(params.row.startTime, 'YYYY-MM-DD') }</span>)
          }
        },
        {
          title: '结束时间',
          key: 'endTime',
          sortable: 'custom',
          render: (h, params) => {
            return (<span> { formatDate(params.row.endTime, 'YYYY-MM-DD') }</span>)
          }
        }
      ],
      // 编辑新增弹窗
      dialogFormVisible: false,
      // 编辑传递的ID
      editId: -1,
      // 检索条件
      searchObj: {
        s_deleteFlag: false,
        s_isUserOrg: true
      }
    }
  },
  created() {
    this.fetch()
  },
  methods: {
    // 表格编辑按钮点击事件处理
    edit(id) {
      // 打开对话框
      this.editId = id
      this.dialogFormVisible = true
      // 更新当前被编辑实体的ID，自动传递至编辑表单
    },
    // 编辑资产对话框确认事件处理
    ok() {
      this.refresh()
      // 关闭对话框
      this.editId = -1
      this.$refs.editForm.reset()
      this.dialogFormVisible = false
    },
    cancel() {
      this.refresh()
      this.editId = -1
      this.$refs.editForm.reset()
      // 关闭对话框
      this.dialogFormVisible = false
    }
  }
}
</script>
